package com.hbvtc.xxxy.nikeSale.frames;
/*
 * 删除员工信息
 */
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.hbvtc.xxxy.nikeSale.daos.GoodsDao;
import com.hbvtc.xxxy.nikeSale.daos.SalesmanDao;
import com.hbvtc.xxxy.nikeSale.utils.DbManager;

public class DelSalesmanNike extends JFrame implements ActionListener{
	JLabel lalId;
	JTextField txtId;
	JButton btnDel;
	Connection conn;
	PreparedStatement pst;
	ResultSet rs;
	String sql;
	public DelSalesmanNike() {
		this.setTitle("删除员工信息");
		this.setSize(1000, 700);
		this.setLocationRelativeTo(null);
		this.setVisible(true);

		// 设置标题栏的图标
		ImageIcon imageIcon = new ImageIcon(getClass().getResource("01.png"));
		this.setIconImage(imageIcon.getImage());

		// 背景图片的路径
		String path = "images/001.jpg";
		ImageIcon background = new ImageIcon(path);
		// 把背景图片显示在一个标签里面
		JLabel label = new JLabel(background);
		// 把标签的大小位置设置为图片刚好填充整个面板
		label.setBounds(0, 0, this.getWidth(), this.getHeight());
		// 把内容窗格转化为JPanel，否则不能用方法setOpaque()来使内容窗格透明
		JPanel imagePanel = (JPanel) this.getContentPane();
		imagePanel.setOpaque(false);
		// 把背景图片添加到分层窗格的最底层作为背景
		this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
		
		this.setLayout(null);
		lalId = new JLabel("员 工 编 号:");
		txtId = new JTextField();
		btnDel = new JButton("删   除");

		this.add(lalId);
		this.add(btnDel);
		this.add(txtId);

		lalId.setBounds(150, 170, 200, 60);
		lalId.setFont(new Font(null, 0, 24));
		txtId.setBounds(400, 180, 220, 40);
		txtId.setFont(new Font(null, 0, 24));

		btnDel.setBounds(550, 450, 170, 40);
		btnDel.setFont(new Font(null, 0, 24));
		
		//触发器按钮添加
		btnDel.addActionListener(this);
	}

	public static void main(String[] args) {
		new DelSalesmanNike().setVisible(true);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		int n=JOptionPane.showConfirmDialog(null, "确认删除吗?","确认删除框",JOptionPane.YES_NO_CANCEL_OPTION);
		if(n==JOptionPane.YES_OPTION){
			int id=Integer.parseInt(txtId.getText().trim());
			SalesmanDao salesmanDao=new SalesmanDao();
			conn=DbManager.getconn();
			sql="delete from salesman where SalesmanId=?;";				
			try {
				pst=conn.prepareStatement(sql);
				pst.setInt(1, id);
				if(salesmanDao.getBySalesmanId(id)==false){
					pst.execute();
					JOptionPane.showMessageDialog(DelSalesmanNike.this, "删除员工成功");
				}else {
					JOptionPane.showMessageDialog(DelSalesmanNike.this, "删除员工失败");
				}
			}catch (Exception e1) {
				// TODO: handle exception
			}
		}
		if(n==JOptionPane.NO_OPTION){
			System.exit(0);
		}		
	}
}
